import os
import json
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QLabel
from PyQt5.QtGui import QIcon  

class SystemInfoWidget(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("系统信息")
        self.setWindowIcon(QIcon('logo.png'))
        self.layout = QVBoxLayout()
        self.setLayout(self.layout)

        self.display_system_info()

    def display_system_info(self):
        # 读取版本号
        with open('/opt/update/local_version.json', 'r') as f:
            version_data = json.load(f)
        version_label = QLabel(f"梦希操作系统版本: {version_data['version']}")
        self.layout.addWidget(version_label)

        # 读取CPU型号
        cpu_model = os.popen('osfetch | grep CPU').read().strip()
        cpu_label = QLabel(f"{cpu_model}")
        self.layout.addWidget(cpu_label)

        # 读取机器主板型号
        board_model = os.popen('cat /sys/class/dmi/id/product_name').read().strip()
        board_label = QLabel(f"机器型号: {board_model}")
        self.layout.addWidget(board_label)

        # 读取内存信息
        mem_info = os.popen('osfetch | grep 内存').read().strip()
        mem_label = QLabel(f"{mem_info}")
        self.layout.addWidget(mem_label)

        # 读取GPU信息
        gpu_info = os.popen('lspci | grep -i "VGA\|3D\|2D"').read().strip()
        gpu_label = QLabel(f"GPU: {gpu_info}")
        self.layout.addWidget(gpu_label)

        # 读取内核版本
        kernel_version = os.uname().release
        kernel_label = QLabel(f"内核版本: {kernel_version}")
        self.layout.addWidget(kernel_label)

        # 读取机器名
        machine_name = os.uname().nodename
        machine_label = QLabel(f"机器名: {machine_name}")
        self.layout.addWidget(machine_label)

        # 读取开机时间
        uptime = os.popen('uptime -p').read().strip()
        uptime_label = QLabel(f"开机时间: {uptime}")
        self.layout.addWidget(uptime_label)

        # 读取分辨率
        resolution = os.popen('osfetch | grep 分辨率').read().strip()
        resolution_label = QLabel(f"{resolution}")
        self.layout.addWidget(resolution_label)

        # 读取用户主文件夹地址
        home_dir = os.path.expanduser("~")
        home_dir_label = QLabel(f"用户主文件夹地址: {home_dir}\n© ZhongHongSoftware 开发\n梦希操作系统及其用户界面受GPLV3开源协议保护")
        self.layout.addWidget(home_dir_label)

if __name__ == "__main__":
    app = QApplication([])
    widget = SystemInfoWidget()
    widget.show()
    app.exec_()